#!/usr/bin/env python3

import rclpy
from rclpy.node import Node
from std_msgs.msg import String

class WelcomeSubscriber(Node):
    
    def __init__(self):
        super().__init__('welcome_subscriber')
        self.subscription = self.create_subscription(
            String,
            'welcome_topic',
            self.listener_callback,
            10)
        self.subscription  # prevent unused variable warning
        self.get_logger().info('Subscriber node has been started. Waiting for messages...')
    
    def listener_callback(self, msg):
        self.get_logger().info(f'Received: "{msg.data}"')


def main(args=None):
    rclpy.init(args=args)
    
    welcome_subscriber = WelcomeSubscriber()
    
    try:
        rclpy.spin(welcome_subscriber)
    except KeyboardInterrupt:
        pass
    
    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    welcome_subscriber.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()